"use strict";

function testSerialPortAndReadline() {
    const SerialPort = require("serialport");
    const ReadLine = require("readline");
    const readline = ReadLine.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    async function question(msg) {
        return new Promise((resolve, reject) => {
            readline.question(msg, (answer) => {
                resolve(answer);
            });
        });
    }
    (async function selectPort() {
        let portInfos = await SerialPort.list();
        for (let i = 0; i < portInfos.length; i++) {
            console.log(portInfos[i]);
        }
        let answer = await question("Input:");
        console.log(answer);
    })();
}

//testSerialPortAndReadline();

// fuck, 不行
function testPromiseForSync() {
    let p = new Promise((resolve, reject) => {

    });
    async function waitForPromiseDone() {
        console.log("waitForPromiseDone begin");
        await p;
        console.log("waitForPromiseDone end");
    }

    console.log("invoke waitForPromiseDone begin");
    waitForPromiseDone();
    console.log("invoke waitForPromiseDone end");
    p.done();
}
// testPromiseForSync();
